package com.lhn.test;

import org.apache.http.HttpHost;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;
import java.util.Map;

/**
 * es 客户端-创建索引
 *
 * @author lhn
 * @date 2022/07/27 22:23
 * @since 1.0.0
 **/
public class ESTest_Doc_Get {

    public static void main(String[] args) throws IOException {
        RestHighLevelClient restHighLevelClient = null;
        try {
            restHighLevelClient = new RestHighLevelClient(RestClient.builder(new HttpHost("106.15.191.175", 9200, "http")));

            // 查询数据
            GetRequest request = new GetRequest();
            request.index("user").id("1001");

            GetResponse response = restHighLevelClient.get(request, RequestOptions.DEFAULT);
            System.out.println(response.getSourceAsString());

        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            assert restHighLevelClient != null;
            restHighLevelClient.close();
        }
    }

}